<?php
class MapAction extends BaseAction {
	/**
	 * 默认动作显示大地图
	 *
	 */
	public function index() {
		$map = D('Citylist');
		$maplist = $map->findall();
		$this->assign('city', $maplist);
		$this->display();
	}

	/**
	 * 根据cid显示城市地图
	 *
	 */
	public function city(){
		$cid = $_GET['cid'];
		if($cid == ''){
			$this->redirect('index');
		}
		else {
			$city = D('Citymap');
			$maplist = $city->findall("cid='$cid'");
			//$maxx = $city->max("x","cid='$cid'");
			//$maxy = $city->max("y","cid='$cid'");
			//$this->assign('width',$mapx * 32);
			//$this->assign('height',$mapy * 32);
			//$this->assign('maxy',$maxy);
			//$this->assign('maxy',$maxy);
			$this->assign('map',$maplist);
			$this->display();
		}
	}

	/**
	 * 购买土地
	 *
	 */
	public function goumaitudi(){
		$mid = $_GET['mid'];
		if($mid == ''){
			$this->redirect('index');
		}
		else {
			$city = D('Citymap');
			$city->find("mid='$mid'");
			$cid = Session::get('cid');
			$char = D('Charbase');
			$char->find("cid='$cid'");
			if($char->money >= $city->price){
				$char->money -= $city->price;
				$char->save();
				$city->belongscid = $cid;
				$city->save();
				$this->redirect('index');
			}
			else {
				$this->showmessage('钱不够');
			}
		}
	}
}
?>